{% extends site.theme|stringformat:"s/include/base.html" %}
{% block title %}配置新产品{% endblock %}{% block script %}
<style type="text/css">
</style>
<script src="/static/dialog/lhgdialog.min.js?self=true" type="text/javascript"></script>
<script src="/static/{{site.theme}}/js/utilitydlg.js" type="text/javascript"></script>
{% endblock %}{% block mainer %}
<div style="float:right; padding:3px;">
	<table class="editTable" style="width:360px; ">
			<thead><tr><th><div>参数名</div></th><th><div>参数值</div></th><th width="70px"><div>操作</div></th></tr></thead>
			{% if productForm.id > 0 %}{% for e in paramList %}
			<tr id="e-{{e.id}}" class="formTr"><th>{{e.title}}：</th><td>{{e.value}}{{e.value1|default:''}}</td><td><a href="javascript:delParam('','Product',{{e.id}});">删除</a> <a href="javascript:editElement({{e.id}});">编辑</a></td></tr>
			{% endfor %}{%endif%}
	</table>
	<input id="btnOK" type="button" onclick="addParam();" value="添加参数">
	<div id="tb_param" style="display:none;"><form><table class="detailTable">{{productParamForm}}</table></form></div>
<script type="text/javascript">
<!-- 
	function addParam(){
		var product_id = {{productForm.id}};
		if(product_id <= 0){
			alert('请先添加产品，然后再添加参数！');
			return;
		}
		var api = $.dialog({
			id:'addDlg', title:'添加参数',
			content: $('#tb_param').html(),
			max: false, min: false, lock: true,
			okVal: '增加',
		    ok: function(){
		    	var thisDlg = this;
		    	$.post('/addParam!Product.do', 'product_id='+product_id+'&'+$('form',thisDlg.DOM.content).serialize(), 
	    			function(data){
			    		if(data.flag){$.dialog.alert(data.msg, function(){thisDlg.close();;thisDlg.reload();});}
	      				else{$.dialog.alert(data.msg);}
	      			},'json');
		    	return false;
		    },
		    cancel: true
		});
	}
	function editElement(id){
		formStr = '&_retType=json';
		var url = 'url:/detailProduct-'+id+'.html';
		var api = $.dialog({
			id:'editDlg', title:'编辑栏目',
			content: url,
			max: false, min: false, lock: true,
			init: function(){
				levelObj = $('#id_level', this.iwin.document.body);
				if(levelObj.val()==20){$('#id_islast', this.iwin.document.body).attr('disabled',true);formStr+="&islast=on"}
				formStr +=  "&level="+levelObj.val();
				levelObj.attr('disabled',true);
			},
			okVal: '编辑',
		    ok: function(){
		    	var thisDlg = this;
		    	$.post('/editParam!Product.do', 'product_id={{productForm.id}}&'+$('form', thisDlg.iwin.document.body).serialize()+formStr, 
	    			function(data){
	      				if(data.flag){$.dialog.alert(data.msg, function(){thisDlg.close();thisDlg.reload();});}
	      				else{$.dialog.alert(data.msg);}
	      			},'json');
		    	return false;
		    },
		    cancel: true
		});
	}
	function delParam(pre,action,id){
		$("#e-"+id).attr('bgcolor','red');
		$.dialog.confirm('确定要删除此项么?',
				function(){
					var url="/"+pre+"/delParam!"+action+"-"+id+".do";
					if(pre=='')url="/delParam!"+action+"-"+id+".do";
					$.post(url, {_retType:"json"},function (data){
								if(data.flag){$("#e-"+id).attr('bgcolor','red').fadeOut("slow",function(){$(this).remove();});}
								else $.dialog.alert(data.msg, function(){$("#e-"+id).removeAttr('bgcolor');});
					},'json');
				},
				function(){$("#e-"+id).removeAttr('bgcolor');}
		);
	}
//-->
</script>
</div>
<div style="padding:3px;">
	<form action="/edit!Product.do" method="post" view="Product">
		<table class="editTable">
			<thead><tr><th colspan="2"><div>内容</div></th></tr></thead>
			<tr class="formTr"><td class="formLabel">{{productForm.title.label}}:</td><td class="formField2">{{productForm.title}}{{productForm.title.errors}}</td></tr>
			<tr class="formTr"><td class="formLabel">{{productForm.catalog.label}}:</td><td class="formField2">{{productForm.catalog}}{{productForm.catalog.errors}}<span class="formLabel2">{{productForm.status.label}}:</span>{{productForm.status}}{{productForm.status.errors}}</td></tr>
			<tr class="formTr"><td class="formLabel">{{productForm.name.label}}:</td><td class="formField2"><span class="formField8">{{productForm.name}}</span>{{productForm.name.errors}}<span class="formLabel2">{{productForm.isComment.label}}:</span>{{productForm.isComment}}<span class="formLabel2">{{productForm.isShow.label}}:</span>{{productForm.isShow}}</td></tr>
			<tr class="formTr"><td class="formLabel">{{productForm.frontcover.label}}:</td><td class="formField2">{{productForm.frontcover}}{{productForm.frontcover.errors}}<a href="javascript:openImgDlg(null, null);">选择图片</a>   <a href="javascript:clearImg(null, null);">清空</a></td></tr>
			<tr class="formTr"><td class="formLabel">{{productForm.content.label}}:</td><td class="formField">{{productForm.content}}{{productForm.content.errors}}</td></tr>
			<tr class="formTr"><td></td><td class="formBtn"><input id="btnOK" type="submit" value="提交"><input type="reset" value="重置">
								<input name="_id"  id="_id" type="Hidden" value="{{productForm.id}}">
			</td></tr>
		</table>
	</form>
</div>
<script type="text/javascript">
<!-- 
bindFrontcover();
//-->
</script>

{% endblock %}